//
//  ZaiXianFuDaoTianJiaXueShengHeaderView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/22.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "ZaiXianFuDaoTianJiaXueShengHeaderView.h"

@implementation ZaiXianFuDaoTianJiaXueShengHeaderView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self initSubView];
        [self layout];
    }
    return self;
}
- (void)initSubView{
    self.backgroundColor = [UIColor whiteColor];
//    [self addSubview:self.serchTF];
//    [self addSubview:self.segment];
    [self addSubview:self.titleLabel];
    [self addSubview:self.titleView];
    [self addSubview:self.gongHaoView];
    [self addSubview:self.nameView];
    [self addSubview:self.searchButton];
    
}
- (void)layout{
//    [_serchTF mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(self.mas_centerX);
//        make.width.equalTo(@350);
//        make.height.equalTo(@30);
//        make.top.equalTo(@20);
//    }];
//    [_segment mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(self.mas_centerX);
//        make.height.equalTo(@40);
//        make.width.equalTo(@350);
//        make.top.equalTo(self->_serchTF.mas_bottom).offset(15);
//    }];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(@10);
        make.width.equalTo(@100);
        make.height.equalTo(@20);
    }];
    [_titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.bottom.equalTo(self.mas_bottom);
        make.height.equalTo(@44);
    }];
    [_gongHaoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_centerX).offset(-50);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@100);
        make.height.equalTo(@40);
    }];
    [_nameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_centerX).offset(50);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@100);
        make.height.equalTo(@40);
    }];
    [_searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-82);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@75);
        make.height.equalTo(@30);
    }];
    _lineViewL = [[UIView alloc]init];
    _lineViewL.backgroundColor = LINCOLOR;
    [self addSubview:_lineViewL];
    [_lineViewL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self->_gongHaoView.mas_right);
        make.top.equalTo(self->_gongHaoView.mas_bottom);
        make.width.equalTo(@120);
        make.height.equalTo(@1);
    }];
    _lineViewR = [[UIView alloc]init];
    _lineViewR.backgroundColor = LINCOLOR;
    [self addSubview:_lineViewR];
    [_lineViewR mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self->_nameView.mas_right);
        make.top.equalTo(self->_nameView.mas_bottom);
        make.width.equalTo(@120);
        make.height.equalTo(@1);
    }];
}
//- (LWQSearchView *)serchTF{
//    if (!_serchTF) {
//        LWQSearchView *view = [[LWQSearchView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 30) initWithType:0 andImageName:@"search_buke"];
//        _serchTF = view;
//    }
//    return _serchTF;
//}
- (XuanZeKeShiDefultView *)gongHaoView{
    if (!_gongHaoView) {
        XuanZeKeShiDefultView *banJiMingChengView = [[XuanZeKeShiDefultView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
        banJiMingChengView.leftTitleLabel.text = @"工号:";
        banJiMingChengView.hidden = YES;
        [banJiMingChengView.leftTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(banJiMingChengView.mas_centerX).offset(-70);
            make.width.equalTo(@60);
            make.height.equalTo(@40);
            make.centerY.equalTo(banJiMingChengView.mas_centerY);
        }];
        [banJiMingChengView.rightDetailTF mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(banJiMingChengView.leftTitleLabel.mas_right);
            make.width.equalTo(@60);
            make.height.equalTo(@40);
            make.centerY.equalTo(banJiMingChengView.mas_centerY);
        }];
        _gongHaoView = banJiMingChengView;
    }
    return _gongHaoView;
}
- (XuanZeKeShiDefultView *)nameView{
    if (!_nameView) {
        XuanZeKeShiDefultView *banJiMingChengView = [[XuanZeKeShiDefultView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
        banJiMingChengView.leftTitleLabel.text = @"姓名:";
        banJiMingChengView.hidden = YES;
        [banJiMingChengView.leftTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(banJiMingChengView.mas_centerX).offset(-70);
            make.width.equalTo(@60);
            make.height.equalTo(@40);
            make.centerY.equalTo(banJiMingChengView.mas_centerY);
        }];
        [banJiMingChengView.rightDetailTF mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(banJiMingChengView.leftTitleLabel.mas_right);
            make.width.equalTo(@60);
            make.height.equalTo(@40);
            make.centerY.equalTo(banJiMingChengView.mas_centerY);
        }];
        _nameView = banJiMingChengView;
    }
    return _nameView;
}
- (UIButton *)searchButton{
    if (!_searchButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"查询" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        [button setBackgroundColor:[UIColor whiteColor]];
        [button setTitleColor:SELECTEDCOLOR forState:UIControlStateNormal];
        button.layer.cornerRadius = 5;
        button.layer.masksToBounds = YES;
        button.layer.borderColor  =SELECTEDCOLOR.CGColor;
        button.layer.borderWidth = 1;
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        button.hidden = YES;
        [button addTarget:self action:@selector(searchClick:) forControlEvents:UIControlEventTouchUpInside];
        _searchButton = button;
    }
    return _searchButton;
}
- (void)searchClick:(UIButton *)sender{
    self.searchBlock(_nameView.rightDetailTF.text,_gongHaoView.rightDetailTF.text);
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text = @"小组成员";
        label.textColor = TITLECOLOR;
        label.font = [UIFont systemFontOfSize:14];
        label.textAlignment = 1;
        _titleLabel = label;
    }
    return _titleLabel;
}
- (SJXQHeaderTitleView *)titleView{
    if (!_titleView) {
        _titleView = [[SJXQHeaderTitleView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 44) andArray:@[@"学号",@"姓名",@"性别",@"联系人",@"电话",@"状态",@"入学日期",@"移除"]];
        _titleView.backgroundColor = CONTENTBACKCOLOR;
    }
    _titleView.frame = CGRectMake(0, 0, self.frame.size.width, 44);
    return _titleView;
}

//- (UISegmentedControl *)segment{
//    if (!_segment) {
//        UISegmentedControl *control = [[UISegmentedControl alloc]initWithItems:@[@"姓名",@"学号"]];
//        control.selectedSegmentIndex = 0;
//        [control addTarget:self action:@selector(chengeSegment:) forControlEvents:UIControlEventValueChanged];
//        control.tintColor = SELECTEDCOLOR;
//        [control setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}forState:UIControlStateSelected];
//
//        [control setTitleTextAttributes:@{NSForegroundColorAttributeName:SELECTEDCOLOR,NSFontAttributeName:[UIFont boldSystemFontOfSize:14.0f]}forState:UIControlStateNormal];
//        _segment = control;
//    }
//    return _segment;
//}
//- (void)chengeSegment:(UISegmentedControl *)control{
//
//}
@end
